package com.zbkj.service.service.project.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.zbkj.common.model.project.EstimateFun;
import com.zbkj.common.model.project.EstimateFundoc;
import com.zbkj.service.dao.project.EstimateFundocMapper;
import com.zbkj.service.service.project.EstimateFundocService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 功能描述-索引文档 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-10-08
 */
@Service
public class EstimateFundocServiceImpl extends ServiceImpl<EstimateFundocMapper, EstimateFundoc> implements EstimateFundocService {

    @Override
    public void updateSatusToHis(Long projectId) {
        if(Objects.isNull(projectId)) {
            return;
        }
        LambdaUpdateWrapper<EstimateFundoc> updateWrappr = new LambdaUpdateWrapper<>();
        updateWrappr.set(EstimateFundoc::getStatus,1)
                .eq(EstimateFundoc::getDeleteFlag, 0)
                .eq(EstimateFundoc::getStatus, 0)
                .eq(EstimateFundoc::getProjectId,projectId);
        this.update(updateWrappr);
    }

    @Override
    public List<EstimateFundoc> getFundocList(Long projectId, String aireqNo) {
        if(Objects.isNull(projectId)) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<EstimateFundoc> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EstimateFundoc::getDeleteFlag, 0)
                .eq(EstimateFundoc::getStatus, 0)
                .eq(EstimateFundoc::getProjectId,projectId);
        if(StringUtils.isNotBlank(aireqNo)) {
            wrapper.eq(EstimateFundoc::getReqNo,aireqNo);
        }
        wrapper.orderByAsc(EstimateFundoc::getIdx);
        return this.list(wrapper);
    }
}
